﻿//*** Guidance generated code ***//
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using ProjectBase.Core;

using Survey.Common.Validation;

namespace Survey.Business
{
    public class RuleCollection<TItem>
        where TItem : class
    {
        #region members
        readonly IList<IValidationRule<TItem>> Rules = new List<IValidationRule<TItem>>();
        #endregion members

        public void Add(IValidationRule<TItem> item)
        {
            Rules.Add(item);
        }

        public IEnumerable<IValidationRule<TItem>> Select(ValidateOn validateOn, ApplyOn applyOn)
        {
            return Rules
                .Where(r => (r.ValidateOn & validateOn).Equals(validateOn))
                .Where(r => (r.ApplyOn & applyOn).Equals(applyOn))
                .OrderBy(r => r.Order)
                ;
        }
    }
}
